import re
import load_config
import chat_geek_info
import logging
import requests
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from view_geek_info import random_sleep_time
import feishu_bot
import get_boss_filterByLabel

def view_resumes(driver, file_path='data/dynamic_ids_s.txt'):
    try:
        try:
            # 打完招呼点击取消筛选
            filter = WebDriverWait(driver, 10).until(
                EC.element_to_be_clickable((By.XPATH, '//*[@id="headerWrap"]/div/div/div[5]/div/div/div'))
            )
            # 创建 ActionChains 对象
            actions = ActionChains(driver)
            # 将鼠标移动到目标元素并点击
            actions.move_to_element(filter).click().perform()
            logging.info("取消筛选")
            random_sleep_time()
        except Exception as e:
            logging.error(f"推荐牛人页面已经取消筛选")

        driver.switch_to.default_content()
        # 获取当前页面 URL
        current_urls = driver.current_url
        # 沟通页面的 url
        recommend_page_urls = 'https://www.zhipin.com/web/chat/index'

        get_boss_filterByLabel.get_boss_filterByLabel(driver)

        # 如果当前页面已经是推荐牛人页面，则跳过点击
        if recommend_page_urls in current_urls:
            logging.info("已经在沟通页面，不需要再次点击")
        else:
            # 点击切换页面
            refresh_btn = driver.find_element(By.XPATH, '//*[@id="wrap"]/div[1]/div[1]/dl[4]/dt/a')
            # 创建 ActionChains 对象
            actions = ActionChains(driver)
            # 将鼠标移动到目标元素并点击
            actions.move_to_element(refresh_btn).click().perform()

            # 等待页面加载
            random_sleep_time()
            logging.info("切换沟通页面")
        # 读取txt文件内容
        with open(file_path, 'r') as file:
            dynamic_ids = file.readlines()
            # 用一个集合来记录已经点击过的 dynamic_id
            clicked_ids = set()

        # 遍历每个动态 ID
        for dynamic_id in dynamic_ids:
            # 循环次数
            if len(clicked_ids) >= 50:
                break
            dynamic_id = dynamic_id.strip()  # 去除换行符
            if dynamic_id.endswith('-0'):  # 判断ID最后一位是否为0
                # ai/process/detail请求数据
                agent_id = load_config.config('agent', 'agent_id')
                access_token = load_config.config('agent', 'access_token')
                user_id = dynamic_id
                # 使用正则表达式去掉下划线、连字符及后面的数据
                user_id_clean = re.sub(r'[^0-9]', '', user_id)
                url = "https://testadminapi2.lanlingapp.cn/ai/process/detail?user_id=" + user_id_clean
                headers = {"accept": "application/json, text/plain, */*", "agent-id": agent_id,
                           "agent-token": access_token}
                # 发送请求
                response = requests.get(url, headers=headers)

                task_greeting = -1
                exchange_phone = -1
                exchange_wechat = -1
                exchange_resume = -1

                # 检查响应状态码
                if response.status_code == 200:
                    # 成功响应，解析响应的 JSON 数据
                    response_data = response.json()

                    # 检查 data 是否为空或包含元素
                    if response_data.get('data'):
                        # 如果 data 不为空，则直接获取 greeting 的值
                        greeting = response_data['data'].get('greeting', None)  # 获取 greeting，若不存在则返回 None
                        task_greeting = greeting if greeting is not None else -1  # 如果 greeting 为 None，则设置为 0
                    else:
                        print("data 列表为空，无法获取 greeting")
                elif response.status_code == 404:
                    print("请求失败，状态码: 404")
                else:
                    print(f"请求失败，状态码: {response.status_code}")
                    print(response.text)  # 打印失败的响应内容

                try:
                    # 等待容器元素加载完成
                    wait = WebDriverWait(driver, 10)  # 等待最多10秒
                    container = wait.until(EC.presence_of_element_located((By.XPATH,
                                                                           '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[1]/div[2]/div')))
                    # 清空浏览器日志缓冲区
                    driver.get_log("performance")

                    # 通过动态ID查找目标元素
                    target_element = container.find_element(By.XPATH, f'//*[@id="{dynamic_id}"]')
                    random_sleep_time()

                    # 创建 ActionChains 对象
                    actions = ActionChains(driver)
                    # 将鼠标移动到目标元素并点击
                    actions.move_to_element(target_element).click().perform()

                    logging.info(f"已点击ID为 {dynamic_id} 的列表详情页面按钮，正在等待内容加载...")
                    logging.info("内容已加载完成")

                    chat_geek_info.chat_geek_info(driver)  # 获取chat_geek_info数据
                    # view_geek_info.view_geek_info(driver, dynamic_id)  # 获取view_geek_inf数据（牛人分析器）

                #     url = "http://192.168.0.132:7018/ai/resume/add"
                #     headers = {"accept": "application/json, text/plain, */*"}
                #     data = {
                #         "agent_id": agent_id,
                #         "encrypt_job_id": encrypt_job_id,
                #         "job_id": job_id,
                #         "job_name": job_name,
                #         "position_name": position_name,
                #         "job_audit_status": job_audit_status,
                #         "auth_token": auth_token
                #     }
                #
                #     # 发送 post 请求
                #     response = requests.post(url, headers=headers, data=data)
                #
                #     # 检查响应状态码
                #     if response.status_code == 200:
                #         # 成功响应，解析响应的 JSON 数据
                #         # response_data = response.json()
                #         print(response)
                #
                #     else:
                #         print(f"请求失败，错误信息: {response_data.get('message')}")
                #
                except Exception as e:
                    print(f"请求失败，状态码: {response.status_code}")

                try:
                    # 获取请求微信状态
                    for k in range(1, 11):
                        msg_paths = f'//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[2]/div[2]/div[{k}]/div/div'
                        msg_paths_element = driver.find_element(By.XPATH, msg_paths)
                        msg_paths_texts = msg_paths_element.text
                        if '请求交换微信已发送':
                            logging.info(f'{dynamic_id}存在请求微信已发送')
                except Exception as e:
                    print(f"{k}元素不存在")

                try:
                    # 如果点击成功，则滚动到目标元素
                    driver.execute_script("arguments[0].scrollIntoView();", target_element)
                    random_sleep_time()

                    # # 查看电话
                    # Check_phone_number_xpath = '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[2]/span[1]'
                    # Check_phone_number_element = driver.find_element(By.XPATH, Check_phone_number_xpath)
                    # Check_phone_number_text = Check_phone_number_element.text
                    #
                    # # 换电话
                    # Chang_phon_number_path = '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[2]/span[1]'
                    # Chang_phon_number_element = driver.find_element(By.XPATH, Chang_phon_number_path)
                    # Chang_phon_number_text = Chang_phon_number_element.text
                    #
                    # # 获取手机号的文本进行保存
                    # if exchange_phone != 2:
                    #     if Check_phone_number_text == "查看电话":
                    #         Check_phone_number_element.click()
                    #         random_sleep_time()
                    #         phone_element_xpath = '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[2]/div/span/span'  # 复制已获取的手机号
                    #         phone_element = driver.find_element(By.XPATH, phone_element_xpath)
                    #         phone_text = phone_element.text
                    #         with open('data/phone_numbers.txt', 'a') as file:
                    #             file.write(str(phone_text) + str({dynamic_id}) + '\n')
                    #             logging.info("电话号码获取成功")
                    #         exchange_phone = 2
                    #
                    #     else:
                    #         # 换电话
                    #         try:
                    #             if Chang_phon_number_text == "换电话":
                    #                 xpath = driver.find_element(By.XPATH,
                    #                                             '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[2]')
                    #                 xpath.click()
                    #                 random_sleep_time()
                    #
                    #                 element = driver.find_element(By.XPATH,
                    #                                               '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[2]/span/span')
                    #                 # 获取该元素的文本
                    #                 element_text = element.text.strip()  # .strip() 去除多余的空格或换行符
                    #                 # 判断文本是否为 "双方回复后可用"
                    #                 if element_text == "交换手机：双方回复后可用":
                    #                     logging.info("双方回复后可用，即将发送消息")
                    #                     # 键盘输入内容
                    #                     if task_greeting == 0:
                    #                         driver.find_element(By.XPATH,
                    #                                             '//*[@id="boss-chat-editor-input"]').send_keys(
                    #                             "你好，我们正在招人，无责底薪5500-6000，绩效1000-2000，住宿2室一厅，包吃住，住宿距离门店五分钟，方便加个微信详细了解一下么？")
                    #                         task_greeting = 1  # 发送消息之后即为1，已经打过招呼
                    #
                    #                 else:
                    #                     logging.info("交换手机请求中")
                    #
                    #         except Exception as e:
                    #             logging.error("双方已聊天，进入换电话阶段")
                    #
                    #         # 换电话
                    #         try:
                    #             if greeting != 2:
                    #                 if Chang_phon_number_text == "换电话":
                    #                     xpath = driver.find_element(By.XPATH,
                    #                                                 '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[2]')
                    #                     xpath.click()
                    #                     random_sleep_time()
                    #
                    #                     xpaths = driver.find_element(By.XPATH,
                    #                                                  '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[2]/div/div/span[2]')
                    #                     # xpaths.click()
                    #                     # 创建 ActionChains 对象
                    #                     actions = ActionChains(driver)
                    #                     # 将鼠标移动到目标元素并点击
                    #                     actions.move_to_element(xpaths).click().perform()
                    #                     logging.info("换电话成功")
                    #                     exchange_phone = 2
                    #
                    #                 else:
                    #                     logging.info("换电话请求中")
                    #
                    #         except Exception as e:
                    #             logging.info("换电话请求中")

                    # 查看微信
                    weixin_number_paths = '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[3]/span[1]'
                    weixin_numbers_element = driver.find_element(By.XPATH, weixin_number_paths)
                    weixin_number_texts = weixin_numbers_element.text

                    # 换微信
                    weixin_number_path = '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[3]/span[1]'
                    weixin_number_element = driver.find_element(By.XPATH, weixin_number_path)
                    weixin_number_text = weixin_number_element.text

                    # # 换微信状态
                    # try:
                    #     weixin_path = '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[3]/span/span'
                    #     weixin_elemenst = driver.find_element(By.XPATH, weixin_path)
                    #     weixin_texts = weixin_elemenst.text
                    #     print(weixin_texts)
                    # except Exception as e:
                    #     print(f"{dynamic_id}元素不存在")

                    # 获取微信号的文本进行保存
                    if exchange_wechat != 2:
                        if weixin_number_texts == "查看微信":
                            # 创建 ActionChains 对象
                            actions = ActionChains(driver)
                            # 将鼠标移动到目标元素并点击
                            actions.move_to_element(weixin_numbers_element).click().perform()
                            random_sleep_time()
                            weixin_element_xpath = '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[3]/div/span/span'  # 复制已获取的微信号
                            weixin_element = driver.find_element(By.XPATH, weixin_element_xpath)
                            weixin_text = weixin_element.text
                            with open('data/weichat_numbers.txt', 'a', encoding='utf-8') as file:
                                file.write(str(weixin_text) + str({dynamic_id}) + '\n')
                                logging.info("微信获取成功")
                            exchange_wechat = 2

                        else:
                            # 换微信
                            try:
                                if weixin_number_text == "换微信":
                                    weixin_xpath = driver.find_element(By.XPATH,
                                                                       '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[3]')

                                    # 创建 ActionChains 对象
                                    actions = ActionChains(driver)
                                    # 将鼠标移动到目标元素并点击
                                    actions.move_to_element(weixin_xpath).click().perform()
                                    random_sleep_time()

                                    weixin_element = driver.find_element(By.XPATH,
                                                                         '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[3]/span/span')
                                    # 获取该元素的文本
                                    weinxin_element_text = weixin_element.text.strip()  # .strip() 去除多余的空格或换行符
                                    # 判断文本是否为 "双方回复后可用"
                                    if weinxin_element_text == "交换微信：双方回复后可用":
                                        logging.info("双方回复后可用，即将发送消息")
                                        # 键盘输入内容
                                        if task_greeting == 0:
                                            # driver.find_element(By.XPATH,
                                            #                     '//*[@id="boss-chat-editor-input"]').send_keys(
                                            #     "你好，我们正在招人，无责底薪5500-6000，绩效1000-2000，住宿2室一厅，包吃住，住宿距离门店五分钟，方便加个微信详细了解一下么？")
                                            task_greeting = 1
                                    else:
                                        logging.info("交换微信请求中")

                            except Exception as e:
                                logging.error("双方已聊天，进入换微信阶段")

                            # 换微信
                            try:
                                if exchange_wechat != 2:
                                    if weixin_number_text == "换微信":
                                        weixinxpath = driver.find_element(By.XPATH,
                                                                          '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[3]')
                                        # 创建 ActionChains 对象
                                        actions = ActionChains(driver)
                                        # 将鼠标移动到目标元素并点击
                                        actions.move_to_element(weixinxpath).click().perform()
                                        random_sleep_time()

                                        if '请求交换微信已发送' in msg_paths_texts:
                                            # 取消确认换微信
                                            weixinxpaths = driver.find_element(By.XPATH,
                                                                               '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[3]/div/div/span[1]')
                                            # 创建 ActionChains 对象
                                            actions = ActionChains(driver)
                                            # 将鼠标移动到目标元素并点击
                                            actions.move_to_element(weixinxpaths).click().perform()
                                            logging.info("请求交换微信已发送，取消成功")
                                            exchange_wechat = 2

                                        else:
                                            # 点击确认换微信
                                            weixinxpaths_S = driver.find_element(By.XPATH,
                                                                                 '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[3]/div/div/span[2]')
                                            # 创建 ActionChains 对象
                                            actions = ActionChains(driver)
                                            # 将鼠标移动到目标元素并点击
                                            actions.move_to_element(weixinxpaths_S).click().perform()
                                            logging.info("换微信成功")
                                            exchange_wechat = 2

                                    else:
                                        logging.info("换微信请求中")

                            except Exception as e:
                                logging.error("换微信请求中")

                    # 将当前 dynamic_id 标记为已点击
                    clicked_ids.add(dynamic_id)

                    # # 获取简历
                    # # 向牛人获取简历
                    # try:
                    #     if exchange_resume != 2:
                    #         if driver.find_element(By.XPATH,
                    #                                '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[1]/div[1]/div[2]/div/div'):
                    #             resume_xpath = driver.find_element(By.XPATH,
                    #                                                '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[1]/div[1]/div[2]/div/div')
                    #             # resume_xpath.click()
                    #             # 创建 ActionChains 对象
                    #             actions = ActionChains(driver)
                    #             # 将鼠标移动到目标元素并点击
                    #             actions.move_to_element(resume_xpath).click().perform()
                    #             random_sleep_time()
                    #
                    #             # 判断是否存在‘双方回复后可以向TA请求’的元素
                    #             if driver.find_element(By.XPATH,
                    #                                    '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/div[1]/div[2]/span'):
                    #                 resumes_xpaths = driver.find_element(By.XPATH,
                    #                                                      '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[1]/div[1]/div[2]/div/div[2]/span')
                    #                 # 获取该元素的文本
                    #                 elements_text = resumes_xpaths.text.strip()  # .strip() 去除多余的空格或换行符
                    #                 # 判断文本是否为 "双方回复后可用"
                    #                 if elements_text == "双方回复后可以向TA请求":
                    #                     logging.info("附件简历请求中，双方回复后可用")
                    #
                    #                 else:
                    #                     logging.info("附件简历请求中")
                    #
                    # except Exception as e:
                    #     logging.info('附件简历获取失败-第一次尝试')
                    #
                    #     #  判断是否有获取点击的元素（双方已回复，获取简历）
                    #     try:
                    #         if exchange_resume != 2:
                    #             if driver.find_element(By.XPATH,
                    #                                    '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[1]/div[1]/div[2]/div/div'):
                    #                 resume_xpath = driver.find_element(By.XPATH,
                    #                                                    '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[1]/div[1]/div[2]/div/div[2]/div[2]/button[2]')
                    #                 # resume_xpath.click()
                    #                 # 创建 ActionChains 对象
                    #                 actions = ActionChains(driver)
                    #                 # 将鼠标移动到目标元素并点击
                    #                 actions.move_to_element(resume_xpath).click().perform()
                    #                 random_sleep_time()
                    #                 logging.info("执行获取简历成功")
                    #     except Exception as e:
                    #         logging.info('附件简历获取失败-第二次尝试')
                    #
                    # # 已获取简历，下载简历
                    # try:
                    #     ck = driver.find_element(By.XPATH,
                    #                              '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[1]/div[1]/div[2]/div/span')
                    #     # ck.click()
                    #     # 创建 ActionChains 对象
                    #     actions = ActionChains(driver)
                    #     # 将鼠标移动到目标元素并点击
                    #     actions.move_to_element(ck).click().perform()
                    #     random_sleep_time()
                    #
                    #     dj = driver.find_element(By.XPATH,
                    #                              '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[1]/div[1]/div[2]/div/span/ul/li[2]')
                    #     # dj.click()
                    #     # 创建 ActionChains 对象
                    #     actions = ActionChains(driver)
                    #     # 将鼠标移动到目标元素并点击
                    #     actions.move_to_element(dj).click().perform()
                    #     random_sleep_time()
                    #
                    #     # 查找并点击简历下载按钮
                    #     if driver.find_element(By.XPATH,
                    #                            '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[1]/div[1]/div[2]/div/a'):
                    #         resumes__xpath = driver.find_element(By.XPATH,
                    #                                              '//*[@id="container"]/div[1]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[1]/div[1]/div[2]/div/a')
                    #         # resumes__xpath.click()
                    #         # 创建 ActionChains 对象
                    #         actions = ActionChains(driver)
                    #         # 将鼠标移动到目标元素并点击
                    #         actions.move_to_element(resumes__xpath).click().perform()
                    #         random_sleep_time()  # 等待页面加载
                    #
                    #         # 如果有新页面，则进行操作
                    #         if len(driver.window_handles) > 1:
                    #             # 跳转新页面，再新页面进行操作
                    #             new_window = driver.window_handles[-1]
                    #             driver.switch_to.window(new_window)
                    #
                    #         # 点击下载附件简历按钮
                    #         resumes_s_xpath = driver.find_element(
                    #             By.XPATH,
                    #             '//*[@id="mainContainer"]/div[6]/div[1]/div/div[2]/button[3]'
                    #         )
                    #         resumes_s_xpath.click()
                    #         logging.info("下载附件简历成功")
                    #         exchange_resume = 2
                    #         random_sleep_time()
                    #
                    #         # 判断是否有多个窗口
                    #         if len(driver.window_handles) > 1:
                    #             # 获取当前窗口句柄
                    #             current_window_handle = driver.current_window_handle
                    #
                    #             # 关闭当前窗口
                    #             driver.close()
                    #
                    #             # 切换到其他窗口
                    #             for handle in driver.window_handles:
                    #                 if handle != current_window_handle:
                    #                     driver.switch_to.window(handle)
                    #                     break  # 切换到另一个窗口
                    #
                    #         else:
                    #             logging.warning("只有一个窗口，无法切换。")
                    #
                    #
                    # except Exception as e:
                    #     logging.error("该简历正在交换中/双方未发送消息")

                except Exception as inner_e:
                    logging.error(f"点击动态 ID {dynamic_id} 时发生错误：{inner_e}")
                    continue

                # 从 [agent] 部分获取 agent_id 和 access_token
                agent_id = load_config.config('agent', 'agent_id')
                access_token = load_config.config('agent', 'access_token')

                user_id = dynamic_id
                # 使用正则表达式去掉下划线、连字符及后面的数据
                user_id_clean = re.sub(r'[^0-9]', '', user_id)

                # 使用获取的 agent_id 和 access_token 构建请求数据
                url = "https://testadminapi2.lanlingapp.cn/ai/process/add"
                headers = {"accept": "application/json, text/plain, */*", "agent-id": agent_id,
                           "agent-token": access_token}
                data = {
                    "user_id": user_id_clean,
                    "greeting": task_greeting,  # '0：未打招呼，1：打招呼'
                    "exchange_phone": exchange_phone,  # '0：未换，1：执行换 2：已获得'
                    "exchange_wechat": exchange_wechat,  # '0：未换，1：执行换 2：已获得'
                    "exchange_resume": exchange_resume,  # '0：未换，1：执行换 2：已获得'
                }

                # 发送请求
                response = requests.post(url, headers=headers, data=data)

                # 检查响应状态码
                if response.status_code == 200:
                    # 成功响应，解析响应的 JSON 数据
                    response_data = response.json()
                    # print(response_data)
                else:
                    print(f"请求失败，状态码: {response.status_code}")

                url = "https://testadminapi2.lanlingapp.cn/ai/process/detail?user_id=" + user_id_clean
                headers = {"accept": "application/json, text/plain, */*", "agent-id": agent_id,
                           "agent-token": access_token}
                # 发送请求
                response = requests.get(url, headers=headers)

                # 检查响应状态码
                if response.status_code == 200:
                    # 成功响应，解析响应的 JSON 数据
                    response_data = response.json()

                    # 检查 data 是否为空或包含元素
                    if response_data.get('data'):
                        # 如果 data 不为空，则直接获取 is_send_lark 的值
                        is_send_lark = response_data['data'].get('is_send_lark', 0)

                        if is_send_lark == 0:
                            send_lark_success = feishu_bot.chat_geek_info()

                            if send_lark_success == 1 :
                                # 使用获取的 agent_id 和 access_token 构建请求数据
                                url = "https://testadminapi2.lanlingapp.cn/ai/process/add"
                                headers = {"accept": "application/json, text/plain, */*", "agent-id": agent_id,
                                           "agent-token": access_token}
                                data = {
                                    "user_id": user_id_clean,
                                    "is_send_lark": 1,
                                }

                                # 发送请求
                                response = requests.post(url, headers=headers, data=data)

                                # 检查响应状态码
                                if response.status_code == 200:
                                    # 成功响应，解析响应的 JSON 数据
                                    response_data = response.json()
                                    # print(response_data)
                                else:
                                    print(f"请求失败，状态码: {response.status_code}")


    except Exception as e:
        logging.error(f"在处理过程中发生错误：{e}")
